/*
 *  $Id: Window.java 3 2008-11-18 20:02:30Z Nathaniel.Waisbrot $
    Copyright (C) 2008  Nathaniel Waisbrot

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package termint.gui.window;

import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.ShellListener;
import org.eclipse.swt.graphics.Drawable;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

/**
 * Essentially used to subclass Shell, which we're prevented from subclassing.
 * @author Nathaniel Waisbrot
 *
 */
public abstract class Window implements Drawable {
	protected final Shell window;
	
	protected Window(Shell parent) {
		window = new Shell(parent);
	}
	protected Window(Shell parent, int styles) {
		window = new Shell(parent, styles);
	}
	protected Window(Window parent) {
		this(parent.window);
	}
	protected Window(Window parent, int styles) {
		this(parent.window, styles);
	}
	protected Window(Display display) {
		window = new Shell(display);
	}
	protected Window(Display display, int styles) {
		window = new Shell(display, styles);
	}
	
	/**
	 * Display the window
	 */
	public void open() {
		window.open();
	}
	
	public void close() {
		window.close();
	}
	
	public void setActive() {
		window.setActive();
	}
	
	public void setSize(int h, int w) {
		window.setSize(h, w);
	}
	
	public void setText(String s) {
		window.setText(s);
	}
	
	/**
	 * Calculate the bounds for this window
	 * @return Rectangle representing the bounds
	 */
	public Rectangle getBounds() {
		return window.getBounds();
	}

	/**
	 * Ask the window to redraw its contents
	 */
	public void redraw() {
		window.redraw();
	}
	
	/**
	 * Remove SWT objects that use system memory
	 */
	public void dispose() {
		window.dispose();
	}
	
	/**
	 * Add a KeyListener to listen for keyboard events on this window
	 * @param l the KeyListener to add
	 */
	public void addKeyListener(KeyListener l) {
		window.addKeyListener(l);
	}
	public void removeKeyListener(KeyListener l) {
		window.removeKeyListener(l);
	}
	
	/**
	 * Add a generic Listener to listen for events on this window
	 * @param eventType the type of SWT event to listen for
	 * @param l the Listener to add
	 */
	public void addListener(int eventType, Listener l) {
		window.addListener(eventType, l);
	}
	public void removeListener(int eventType, Listener l) {
		window.removeListener(eventType, l);
	}
	
	public void addShellListener(ShellListener listener) {
		window.addShellListener(listener);
	}
	public void removeShellListener(ShellListener listener) {
		window.removeShellListener(listener);
	}

	/**
	 * @param selection
	 */
	public void setVisible(boolean b) {
		window.setVisible(b);
	}

	public void setFocus() {
		window.setFocus();
	}
	
	public Point getLocation() {
		return window.getLocation();
	}
	
	public Display getDisplay() {
		return window.getDisplay();
	}
	
	public boolean isVisible() {
		return window.isVisible();
	}
	
	/** for Drawable interface */
	public long internal_new_GC(org.eclipse.swt.graphics.GCData data) {
		return window.internal_new_GC(data);
	}
	/** for Drawable interface */
	public void internal_dispose_GC(long handle, org.eclipse.swt.graphics.GCData data) {
		window.internal_dispose_GC(handle, data);
	}
}
